#include "GhostEnemy.h"
#include <time.h>

GhostEnemy::GhostEnemy()
{
	GameObject::GameObject();
	mIdMacgicSprites = m_idSprite;
	m_radius = 25;

	timeDelay = 10;
	timeOfGame = 0;
	dt = 0.15;
	m_velocity.m_x = 0;
	m_velocity.m_y = -1;
}

GhostEnemy::~GhostEnemy()
{
	// do nothing
}

void GhostEnemy::setPositionPacman(Point &_positionPacman)
{
	mDestination.x = _positionPacman.x;
	mDestination.y = _positionPacman.y;
}

void GhostEnemy::update()
{
	timeOfGame += dt;
	if(timeOfGame > timeDelay)
	{
		m_velocity.m_x = (rand() % 21) - 10;
		m_velocity.m_y = (rand() % 21) - 10;
		timeOfGame = 0;
	}
	int lenght = (mDestination.x - m_position.x)*(mDestination.x - m_position.x) +
		(mDestination.y - m_position.y)*(mDestination.y - m_position.y);

	if (lenght <= (22500))
	{
		m_velocity.m_x = mDestination.x - m_position.x;
		m_velocity.m_y = mDestination.y - m_position.y;
	}
	m_velocity.normalize();

	m_position.x = m_position.x + m_velocity.m_x;
	m_position.y = m_position.y + m_velocity.m_y;

	int dstRectX = m_position.x;
	int dstRectY = m_position.y;

	int dstRectW = 20;
	int dstRectH = 20;

	m_sprite.setDrawingCoordinates(dstRectX, dstRectY, dstRectW, dstRectH, m_idSprite);

	
}